<template>
  <div class="commont-reply">
    <van-nav-bar title="回复">
      <van-icon slot="left" name="cross" @click="$emit('close')"></van-icon>
    </van-nav-bar>

    <div class="content">
      <commont-item :item="commont"></commont-item>
      <van-cell>全部回复</van-cell>
      <commont-list
        :articleId="commont.com_id"
        :list="commontList"
        type="c"
      ></commont-list>
    </div>

    <!-- 添加评论 -->
    <div class="scroll_wrap">
      <van-button class="addReply-btn" slot="small" round @click="isPostShow=true">添加评论</van-button>
    </div>
    <van-popup
    v-model="isPostShow"
    position="bottom"
    >
    <commont-post
      :target='commont.com_id'
      @post-success='onPostSuccess'
    ></commont-post>
    </van-popup>
  </div>
</template>

<script>
import CommontItem from './commont-item.vue'
import CommontList from './commont-list.vue'
import CommontPost from './commont-post.vue'
export default {
  name: 'CommontReply',
  components: {
    CommontItem,
    CommontList,
    CommontPost
  },
  props: {
    commont: {
      type: Object,
      required: true
    }
  },
  data () {
    return {
      commontList: [],
      isPostShow: false
    }
  },
  created () {},
  mounted () {},
  methods: {
    onPostSuccess (data) {
      // 更新回复数量
      this.commont.reply_count++
      // 关闭弹层
      this.isPostShow = false
      // 将最新的回复内容添加到顶部
      this.CommontList.unshift(data.new_obj)
    }
  }
}
</script>

<style scoped lang="less">
.commont-reply {
  .content{
    position: fixed;
    left: 0;
    right: 0;
    top: 100px;
    bottom: 88px;
    overflow-y: auto;
  }
  .scroll_wrap {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    border-top: 1px solid red;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 88px;
    background-color: #fff;
    .addReply-btn {
      width: 60%;
    }
  }
}
</style>
